/**
 * Copyright (C), 2019-2024,  XXX有限公司
 * FileName: WorkDaysAndRestDays
 * Author:   xs
 * Date:     2024/12/5 20:44
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */

package com.koron.util;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WorkDaysAndRestDays {
    private int years;
    private List<LocalDate> workDays;
    private List<LocalDate> restDays;

    public WorkDaysAndRestDays(int years) {
        this.years = years;
        this.workDays = new ArrayList<>();
        this.restDays = new ArrayList<>();
        initialize();
    }

    private void initialize() {
        LocalDate startDate = LocalDate.now();
        LocalDate endDate = startDate.plusYears(years);

        for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
            if (isWorkDay(date)) {
                workDays.add(date);
            } else {
                restDays.add(date);
            }
        }
    }

    private boolean isWorkDay(LocalDate date) {
        return date.getDayOfWeek() != DayOfWeek.SATURDAY && date.getDayOfWeek() != DayOfWeek.SUNDAY;
    }

    public Map<String,Integer> printDays() {
        Map<String,Integer> maps=new HashMap<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
       // System.out.println("工作日：");
        for (LocalDate workDay : workDays) {
            //System.out.println(workDay.format(formatter));
            maps.put(workDay.format(formatter),2);
        }

       // System.out.println("休息日：");
        for (LocalDate restDay : restDays) {
           // System.out.println(restDay.format(formatter));
            maps.put(restDay.format(formatter),1);
        }
        return maps;
    }

    public static void main(String[] args) {
        WorkDaysAndRestDays calendar = new WorkDaysAndRestDays(3);
        calendar.printDays();
    }
}